@extends('layouts.modal')
@section('content')
    <form class="layui-form layui-card" action="" method="post" autocomplete="off">
        <div class="layui-card-body padding-left-40">
            <div class="layui-form-item">
                <label class="relative block">
                    <span class="color-green font-w7">{{ trans('user.loginname') }}</span>
                    <input disabled="" value="{{ session('userinfo.loginname') }}" class="layui-input layui-bg-gray">
                </label>
            </div>
            <div class="layui-form-item">
                <label class="relative block label-required-prev">
                    <span class="color-green font-w7">{{ trans('user.old_password') }}</span>
                    <input type="password" id="oldpassword" name="oldpassword" value="" required=""
                           placeholder="{{ trans('user.please_old_password') }}"
                           class="layui-input validate-error">
                    <span
                        style="padding-right: 12px; color: rgb(169, 68, 66); position: absolute; right: 0px; font-size: 12px; z-index: 2; display: block; width: auto; text-align: center; pointer-events: none; top: 24px; padding-bottom: 0px; line-height: 38px;"
                        class="layui-anim layui-anim-fadein">{{ trans('user.please_old_password') }}</span>
                </label>
            </div>
            <div class="layui-form-item">
                <label class="relative block label-required-prev">
                    <span class="color-green font-w7">{{ trans('user.new_password') }}</span>
                    <input type="password" id="password" name="password"
                           placeholder="{{ trans('user.please_new_password') }}"
                           class="layui-input">
                </label>
            </div>

            <div class="layui-form-item">
                <label class="relative block label-required-prev">
                    <span class="color-green font-w7">{{ trans('user.repeat_login_password') }}</span>
                    <input type="password" id="repassword" name="repassword"
                           placeholder="{{ trans('user.please_repeat_login_password') }}" class="layui-input">
                </label>
            </div>
        </div>
        <div class="layui-form-item"></div>
        <div class="layui-form-item text-center">
            <button class="layui-btn" type="button" onclick="save()">{{ trans('common.save_data') }}</button>
            <button class="layui-btn layui-btn-danger" type="button"
                    onclick="cancel()">{{ trans('common.cancel') }}</button>
        </div>
    </form>

    <script type="text/javascript">
        function cancel() {
            parent.layer.closeAll();
        }

        function save() {
            var data = {};
            var postUrl = "{{ url('user/domodpass') }}";
            var oldpassword = $.trim($("#oldpassword").val());
            var password = $.trim($("#password").val());
            var repassword = $.trim($("#repassword").val());

            if (oldpassword == "") {
                layer.msg("{{ trans('user.oldpassword_empty') }}");
                return false;
            }
            if (password == "") {
                layer.msg("{{ trans('user.password_empty') }}");
                return false;
            }
            if (repassword == "") {
                layer.msg({{ trans('user.repassword_empty') }});
                return false;
            }
            if (password !== repassword) {
                layer.msg("{{ trans('user.repassword_equal_password') }}");
                return false;
            }
            data.password = password;
            data.oldpassword = oldpassword;
            data.repassword = repassword;
            data.id = "{{ session('userinfo.id')}}";

            $.ajax({
                url: postUrl,
                type: 'POST',
                dataType: 'json',
                headers: {
                    'X-CSRF-TOKEN': "{{ csrf_token() }}"
                },
                ContentType: "application/json; charset=utf-8",
                data: data,
                success: function (result) {
                    if (result.code == 0) {
                        layer.msg("{{ trans('common.operation_success') }}", {
                            time: 1000
                        }, function () {
                            parent.layer.closeAll();
                        })
                    } else {
                        layer.msg(result.msg)
                    }
                }
            });
        }
    </script>
@endsection




